package com.example.xianji.activity;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.JsonObjectRequest;
import com.example.xianji.Contant;
import com.example.xianji.XJApplication;
import com.example.xianji.R;
import com.example.xianji.bean.YiJi_Class;
import com.example.xianji.constant.Constant;
import com.example.xianji.utils.sp.PreferenceEngine;
import com.example.xianji.widgets.MyGridView;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.Manifest;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.provider.MediaStore;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 发布产品
 *
 * @author me
 */
public class Main_ChuangJain_ProductActivity extends Activity implements OnClickListener, ActivityCompat.OnRequestPermissionsResultCallback {
    private LinearLayout layout, linearlayout_place, linearlayout_place_name;
    private ListView show_listview;
    private PopupWindow show_popupWindow;
    private Button send_yiji_product_button, send_erji_product_button, send_sanji_product_button,
            send_siji_product_button, zidingyi_yiji_product_button, zidingyi_erji_product_button, product_cuntry,
            yiji_product_palce_button, erji_product_palce_button, sanji_product_palce_button;
    private int cid = 0, pid = 0;
    private ArrayList<YiJi_Class> fenlei_list = new ArrayList<YiJi_Class>();
    private MyAdapter fenlei_Adapter;
    private int yiji_fenlei_id = 0, erji_fenlei_id = 0, sanji_fenlei_id = 0, siji_fenlei_id = 0;
    private int indefine_yiji_id = 0, indefine_erji_id = 0;
    private int product_country_id = 0;//品牌的国家
    private int province_id = 0, city_id = 0, distrct_id = 0;//省份id
    private EditText edittext_product_name, edittext_product_pingpai, edittext_product_style,
            edittext_product_xishu, edittext_product_content, edittext_product_price;
    private TextView text_product_send;
    //    private SharedPreferences sp;
//    private Editor ed;
    private RelativeLayout product_relative_chuangjian_product_back;
    private MyGridView send_product_MyGridView;
    private ImageView send_product_picture;
    private int Request_Permission_Get_Photo = 1;//相册
    private int Request_Permission_Take_Photo = 2;//拍照
    private String photoStr;
    private My_GridView_Adapter mMy_GridView_Adapter = new My_GridView_Adapter();

    private ArrayList<YiJi_Class> bitmap_list = new ArrayList<YiJi_Class>();
    private JSONArray pic_array = new JSONArray();//图片数组
    private JSONArray id_array = new JSONArray();//id数组
    private ProgressDialog pd;
    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                //一级分类列表
                show_listview.setAdapter(fenlei_Adapter);
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        send_yiji_product_button.setText(fenlei_list.get(position).getName());
                        yiji_fenlei_id = fenlei_list.get(position).getId();

                        send_erji_product_button.setText("请选择");
                        send_sanji_product_button.setText("请选择");
                        send_siji_product_button.setText("请选择");
                        show_popupWindow.dismiss();
                    }
                });

            }
            if (msg.what == 2) {

                //二级分类列表
                show_listview.setAdapter(fenlei_Adapter);
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        send_erji_product_button.setText(fenlei_list.get(position).getName());
                        erji_fenlei_id = fenlei_list.get(position).getId();
                        send_sanji_product_button.setText("请选择");
                        send_siji_product_button.setText("请选择");
                        show_popupWindow.dismiss();
                    }
                });
            }
            if (msg.what == 3) {

                //三级分类列表
                show_listview.setAdapter(fenlei_Adapter);
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        send_sanji_product_button.setText(fenlei_list.get(position).getName());
                        sanji_fenlei_id = fenlei_list.get(position).getId();
                        send_siji_product_button.setText("请选择");
                        show_popupWindow.dismiss();
                    }
                });
            }
            if (msg.what == 4) {

                //四级分类列表
                show_listview.setAdapter(fenlei_Adapter);
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        send_siji_product_button.setText(fenlei_list.get(position).getName());
                        siji_fenlei_id = fenlei_list.get(position).getId();
                        show_popupWindow.dismiss();
                    }
                });
            }

            if (msg.what == 5) {

                //自定义一级分类
                show_listview.setAdapter(fenlei_Adapter);
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        zidingyi_yiji_product_button.setText(fenlei_list.get(position).getName());
                        indefine_yiji_id = fenlei_list.get(position).getId();
                        zidingyi_erji_product_button.setText("请选择");
                        indefine_erji_id = 0;
                        show_popupWindow.dismiss();
                    }
                });
            }
            if (msg.what == 6) {

                //自定义二级分类
                show_listview.setAdapter(fenlei_Adapter);
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        zidingyi_erji_product_button.setText(fenlei_list.get(position).getName());
                        indefine_erji_id = fenlei_list.get(position).getId();
                        show_popupWindow.dismiss();
                    }
                });
            }
            if (msg.what == 7) {
                //品牌的国家
                show_listview.setAdapter(fenlei_Adapter);
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        product_cuntry.setText(fenlei_list.get(position).getName());
                        if (fenlei_list.get(position).getName().equals("中国")) {
                            linearlayout_place.setVisibility(View.VISIBLE);
                            linearlayout_place_name.setVisibility(View.VISIBLE);
                        } else {
                            linearlayout_place.setVisibility(View.GONE);
                            linearlayout_place_name.setVisibility(View.GONE);
                        }
                        product_country_id = fenlei_list.get(position).getId();
                        show_popupWindow.dismiss();
                    }
                });
            }
            if (msg.what == 8) {

                //省份
                show_listview.setAdapter(fenlei_Adapter);
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        yiji_product_palce_button.setText(fenlei_list.get(position).getName());
                        province_id = fenlei_list.get(position).getId();
                        erji_product_palce_button.setText("请选择");
                        sanji_product_palce_button.setText("请选择");
                        show_popupWindow.dismiss();
                    }
                });
            }
            if (msg.what == 9) {

                //城市
                show_listview.setAdapter(fenlei_Adapter);
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        erji_product_palce_button.setText(fenlei_list.get(position).getName());
                        city_id = fenlei_list.get(position).getId();
                        sanji_product_palce_button.setText("请选择");
                        show_popupWindow.dismiss();
                    }
                });
            }
            if (msg.what == 10) {

                //地区
                show_listview.setAdapter(fenlei_Adapter);
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        sanji_product_palce_button.setText(fenlei_list.get(position).getName());
                        distrct_id = fenlei_list.get(position).getId();
                        show_popupWindow.dismiss();
                    }
                });
            }
            if (msg.what == 11) {

                //特殊城市
                show_listview.setAdapter(fenlei_Adapter);
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        erji_product_palce_button.setText(fenlei_list.get(position).getName());
                        city_id = fenlei_list.get(position).getId();
                        sanji_product_palce_button.setText("请选择");
                        show_popupWindow.dismiss();
                    }
                });
            }
            if (msg.what == 12) {
                //获取详情后的图片适配器
                send_product_MyGridView.setAdapter(mMy_GridView_Adapter);
            }
        }
    };

    /**
     * 二进制转字符串
     *
     * @param b
     * @return
     */
    public static String byte2hex(byte[] b) {
        StringBuffer sb = new StringBuffer();
        String stmp = "";
        for (int n = 0; n < b.length; n++) {
            stmp = Integer.toHexString(b[n] & 0XFF);
            if (stmp.length() == 1) {
                sb.append("0" + stmp);
            } else {
                sb.append(stmp);
            }


        }
        return sb.toString();

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        setContentView(R.layout.activity_main__chuang_jain__product);
        send_yiji_product_button = (Button) findViewById(R.id.send_yiji_product_button);
        send_erji_product_button = (Button) findViewById(R.id.send_erji_product_button);
        send_sanji_product_button = (Button) findViewById(R.id.send_sanji_product_button);
        send_siji_product_button = (Button) findViewById(R.id.send_siji_product_button);
        zidingyi_yiji_product_button = (Button) findViewById(R.id.zidingyi_yiji_product_button);
        zidingyi_erji_product_button = (Button) findViewById(R.id.zidingyi_erji_product_button);
        product_cuntry = (Button) findViewById(R.id.product_cuntry);
        yiji_product_palce_button = (Button) findViewById(R.id.yiji_product_palce_button);
        erji_product_palce_button = (Button) findViewById(R.id.erji_product_palce_button);
        sanji_product_palce_button = (Button) findViewById(R.id.sanji_product_palce_button);
        edittext_product_name = (EditText) findViewById(R.id.edittext_product_name);
        edittext_product_pingpai = (EditText) findViewById(R.id.edittext_product_pingpai);
        edittext_product_style = (EditText) findViewById(R.id.edittext_product_style);
        edittext_product_xishu = (EditText) findViewById(R.id.edittext_product_xishu);
        edittext_product_content = (EditText) findViewById(R.id.edittext_product_content);
        edittext_product_price = (EditText) findViewById(R.id.edittext_product_price);
        linearlayout_place = (LinearLayout) findViewById(R.id.linearlayout_place);
        text_product_send = (TextView) findViewById(R.id.text_product_send);
        linearlayout_place_name = (LinearLayout) findViewById(R.id.linearlayout_place_name);
        product_relative_chuangjian_product_back = (RelativeLayout) findViewById(R.id.product_relative_chuangjian_product_back);
        send_product_MyGridView = (MyGridView) findViewById(R.id.send_product_MyGridView);
        send_product_picture = (ImageView) findViewById(R.id.send_product_picture);

//        sp = getSharedPreferences("text", MODE_PRIVATE);
//        ed = sp.edit();

        pd = new ProgressDialog(this);

        send_yiji_product_button.setOnClickListener(this);
        send_erji_product_button.setOnClickListener(this);
        send_sanji_product_button.setOnClickListener(this);
        send_siji_product_button.setOnClickListener(this);
        zidingyi_yiji_product_button.setOnClickListener(this);
        zidingyi_erji_product_button.setOnClickListener(this);
        yiji_product_palce_button.setOnClickListener(this);
        erji_product_palce_button.setOnClickListener(this);
        sanji_product_palce_button.setOnClickListener(this);
        text_product_send.setOnClickListener(this);
        product_cuntry.setOnClickListener(this);
        send_product_picture.setOnClickListener(this);
        product_relative_chuangjian_product_back.setOnClickListener(this);
        fenlei_Adapter = new MyAdapter();

        if (getIntent().getIntExtra("product_come_from", 0) == Contant.product_come_from_editor) {
            //来自于编辑页面获取详情
            text_product_send.setText("提交");
            get_product_detail_tag(12);
        }
        send_product_MyGridView.setAdapter(mMy_GridView_Adapter);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.send_yiji_product_button) {
            //产品分类一级
            cid = 0;
            get_fenlei_tag(1);
            Photo_show();
            show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
        } else if (v.getId() == R.id.send_erji_product_button) {
            //产品分类二级
            cid = yiji_fenlei_id;
            if (send_yiji_product_button.getText().toString().equals("请选择")) {
                Toast.makeText(this, "请选择一级分类", Toast.LENGTH_SHORT).show();
            } else {
                get_fenlei_tag(2);
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
            }

        } else if (v.getId() == R.id.send_sanji_product_button) {
            //产品分类三级
            cid = erji_fenlei_id;
            if (send_erji_product_button.getText().toString().equals("请选择")) {
                Toast.makeText(this, "请选择二级分类", Toast.LENGTH_SHORT).show();
            } else {
                get_fenlei_tag(3);
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
            }

        } else if (v.getId() == R.id.send_siji_product_button) {
            //产品分类四级
            cid = sanji_fenlei_id;
            if (send_sanji_product_button.getText().toString().equals("请选择")) {
                Toast.makeText(this, "请选择三级分类", Toast.LENGTH_SHORT).show();
            } else {
                get_fenlei_tag(4);
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
            }
        } else if (v.getId() == R.id.zidingyi_yiji_product_button) {
            //自定义分类一级
            pid = 0;
            get_indefine_tag(5);
            Photo_show();
            show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
        } else if (v.getId() == R.id.zidingyi_erji_product_button) {
            //自定义分类二级
            if (zidingyi_yiji_product_button.getText().toString().equals("请选择")) {
                Toast.makeText(this, "请选择一级分类", Toast.LENGTH_SHORT).show();
            } else {
                pid = indefine_yiji_id;
                get_indefine_tag(6);
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
            }
        } else if (v.getId() == R.id.product_cuntry) {
            //品牌-国家
            get_product_country_tag(7);
            Photo_show();
            show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
        } else if (v.getId() == R.id.yiji_product_palce_button) {
            //省份
            province_id = 0;
            get_province(8);
            Photo_show();
            show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
        } else if (v.getId() == R.id.erji_product_palce_button) {
            //城市
            String province_name = yiji_product_palce_button.getText().toString();
            if (yiji_product_palce_button.getText().toString().equals("请选择")) {
                Toast.makeText(this, "请选择省份", Toast.LENGTH_SHORT).show();
            } else if (yiji_product_palce_button.getText().toString().equals("北京") || yiji_product_palce_button.getText().toString().equals("北京") || yiji_product_palce_button.getText().toString().equals("天津") || yiji_product_palce_button.getText().toString().equals("上海") ||
                    yiji_product_palce_button.getText().toString().equals("香港") || yiji_product_palce_button.getText().toString().equals("台湾")
                    ) {

                get_special_city(11);
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
            } else {

                get_city(9);
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
            }


        } else if (v.getId() == R.id.sanji_product_palce_button) {
            //地区
            if (erji_product_palce_button.getText().toString().equals("请选择")) {
                Toast.makeText(this, "请选择城市", Toast.LENGTH_SHORT).show();
            } else {
                get_distrct(10);
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
            }
        } else if (v.getId() == R.id.text_product_send) {
            if (getIntent().getIntExtra("product_come_from", 0) == Contant.product_come_from_send) {
                //发布产品
                if (product_cuntry.getText().toString().equals("中国")) {
                    if (!yiji_product_palce_button.getText().equals("请选择")) {
                        if (!erji_product_palce_button.getText().equals("请选择")) {
                            if (!sanji_product_palce_button.getText().equals("请选择")) {
                                if (!send_yiji_product_button.getText().equals("请选择")) {
                                    if (!send_erji_product_button.getText().equals("请选择")) {
                                        if (!send_sanji_product_button.getText().equals("请选择")) {
                                            if (!send_siji_product_button.getText().equals("请选择")) {
                                                pd.show();
                                                send_product(12);
                                            } else {
                                                Toast.makeText(this, "请选择四级分类", Toast.LENGTH_SHORT).show();
                                            }
                                        } else {
                                            Toast.makeText(this, "请选择三级分类", Toast.LENGTH_SHORT).show();
                                        }
                                    } else {
                                        Toast.makeText(this, "请选择二级分类", Toast.LENGTH_SHORT).show();
                                    }
                                } else {
                                    Toast.makeText(this, "请选择一级分类", Toast.LENGTH_SHORT).show();
                                }

                            } else {
                                Toast.makeText(this, "请选择地区", Toast.LENGTH_SHORT).show();
                            }

                        } else {
                            Toast.makeText(this, "请选择城市", Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(this, "请选择省份", Toast.LENGTH_SHORT).show();
                    }

                } else {
                    if (!send_yiji_product_button.getText().equals("请选择")) {
                        if (!send_erji_product_button.getText().equals("请选择")) {
                            if (!send_sanji_product_button.getText().equals("请选择")) {
                                if (!send_siji_product_button.getText().equals("请选择")) {
                                    pd.show();
                                    send_product(12);
                                } else {
                                    Toast.makeText(this, "请选择四级分类", Toast.LENGTH_SHORT).show();
                                }
                            } else {
                                Toast.makeText(this, "请选择三级分类", Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            Toast.makeText(this, "请选择二级分类", Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(this, "请选择一级分类", Toast.LENGTH_SHORT).show();
                    }

                }
            } else {
                //编辑产品
                if (product_cuntry.getText().toString().equals("中国")) {
                    if (!yiji_product_palce_button.getText().equals("请选择")) {
                        if (!erji_product_palce_button.getText().equals("请选择")) {
                            if (!sanji_product_palce_button.getText().equals("请选择")) {
                                if (!send_yiji_product_button.getText().equals("请选择")) {
                                    if (!send_erji_product_button.getText().equals("请选择")) {
                                        if (!send_sanji_product_button.getText().equals("请选择")) {
                                            if (!send_siji_product_button.getText().equals("请选择")) {
                                                pd.show();
                                                editor_product(12);
                                            } else {
                                                Toast.makeText(this, "请选择四级分类", Toast.LENGTH_SHORT).show();
                                            }
                                        } else {
                                            Toast.makeText(this, "请选择三级分类", Toast.LENGTH_SHORT).show();
                                        }
                                    } else {
                                        Toast.makeText(this, "请选择二级分类", Toast.LENGTH_SHORT).show();
                                    }
                                } else {
                                    Toast.makeText(this, "请选择一级分类", Toast.LENGTH_SHORT).show();
                                }

                            } else {
                                Toast.makeText(this, "请选择地区", Toast.LENGTH_SHORT).show();
                            }

                        } else {
                            Toast.makeText(this, "请选择城市", Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(this, "请选择省份", Toast.LENGTH_SHORT).show();
                    }

                } else {
                    if (!send_yiji_product_button.getText().equals("请选择")) {
                        if (!send_erji_product_button.getText().equals("请选择")) {
                            if (!send_sanji_product_button.getText().equals("请选择")) {
                                if (!send_siji_product_button.getText().equals("请选择")) {
                                    pd.show();
                                    editor_product(12);
                                } else {
                                    Toast.makeText(this, "请选择四级分类", Toast.LENGTH_SHORT).show();
                                }
                            } else {
                                Toast.makeText(this, "请选择三级分类", Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            Toast.makeText(this, "请选择二级分类", Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(this, "请选择一级分类", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        } else if (v.getId() == R.id.product_relative_chuangjian_product_back) {
            Main_ChuangJain_ProductActivity.this.finish();
        } else if (v.getId() == R.id.send_product_picture) {
            fenlei_list.clear();
            YiJi_Class yiji = new YiJi_Class();
            yiji.setId(0);
            yiji.setName("拍照");
            YiJi_Class yiji1 = new YiJi_Class();
            yiji1.setId(1);
            yiji1.setName("相册");
            YiJi_Class yiji2 = new YiJi_Class();
            yiji2.setId(2);
            yiji2.setName("取消");
            fenlei_list.add(yiji);
            fenlei_list.add(yiji1);
            fenlei_list.add(yiji2);
            Photo_show();
            show_listview.setAdapter(new MyAdapter());
            show_popupWindow.showAtLocation(findViewById(R.id.chuangjian_product), Gravity.BOTTOM, 0, 0);
            show_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    if (fenlei_list.get(position).getName().equals("拍照")) {
                        //拍照
                        show_popupWindow.dismiss();

                        String[] permission_paizhao = {Manifest.permission.CAMERA};
                        if (permissionCheck(permission_paizhao)) {
                            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

                            startActivityForResult(intent, 2);
                        } else {
                            ActivityCompat.requestPermissions(Main_ChuangJain_ProductActivity.this, permission_paizhao, Request_Permission_Take_Photo);
                        }
                    } else if (fenlei_list.get(position).getName().equals("相册")) {
                        //相册
                        show_popupWindow.dismiss();
                        String[] permission_Picture = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
                        if (permissionCheck(permission_Picture)) {
                            Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                            startActivityForResult(intent, 1);
                        } else {
                            ActivityCompat.requestPermissions(Main_ChuangJain_ProductActivity.this, permission_Picture, Request_Permission_Get_Photo);
                        }

                    } else if (fenlei_list.get(position).getName().equals("取消")) {
                        //取消
                        if (show_popupWindow != null) {
                            show_popupWindow.dismiss();
                            show_popupWindow = null;
                        }
                    }
                }
            });
        }
    }

    private boolean permissionCheck(String[] permissionManifest) {
        if (VERSION.SDK_INT >= 23) {
            boolean permissionState = true;
            for (String permission : permissionManifest) {
                if (ContextCompat.checkSelfPermission(this, permission)
                        != PackageManager.PERMISSION_GRANTED) {
                    permissionState = false;
                }
            }
            if (!permissionState) {
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (requestCode == Request_Permission_Take_Photo) {
            //拍照
            if (grantResults.length > 0) {
                boolean take_photo_flag = false;
                for (int i = 0; i < permissions.length; i++) {
                    if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                        take_photo_flag = true;
                    }
                }
                if (take_photo_flag) {
                    //申请成功，可以拍照

                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

                    startActivityForResult(intent, 2);
                } else {
                    Toast.makeText(this, "请先开通权限哦", Toast.LENGTH_SHORT).show();
                }

            }
        } else if (requestCode == Request_Permission_Get_Photo) {
            //相册
            if (grantResults.length > 0) {
                boolean take_photo_flag = false;
                for (int i = 0; i < permissions.length; i++) {
                    if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                        take_photo_flag = true;
                    }
                }
                if (take_photo_flag) {
                    //申请成功，可以获取相册图片
                    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    startActivityForResult(intent, 1);
                } else {
                    Toast.makeText(this, "请先开通权限哦", Toast.LENGTH_SHORT).show();
                }
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (data != null) {
            switch (requestCode) {
                case 1:
                    try {
                        if (data != null) {
                            Uri selectedImage = data.getData();
                            String[] filePathColumns = {MediaStore.Images.Media.DATA};
                            Cursor c = getContentResolver().query(
                                    selectedImage, filePathColumns, null, null, null);
                            c.moveToFirst();
                            int columnIndex = c.getColumnIndex(filePathColumns[0]);
                            String picturePath = c.getString(columnIndex);// 取出图片路径
                            c.close();
                            BitmapFactory.Options opt = new BitmapFactory.Options();
                            opt.inSampleSize = 4; //使用缩略图，缩小倍数
                            Bitmap bitmap = BitmapFactory.decodeFile(picturePath, opt);
                            setPicToView(bitmap);
                        }

                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    break;

                case 2:


                    Bitmap bitmap1 = (Bitmap) data.getExtras().get("data");
                    Log.i("BitmapBitmap", bitmap1 + "");

                    setPicToView(bitmap1);


                    // show(bitmap1);
                    break;

                case 3:

                    break;
                default:


                    break;

            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    /**
     * 将图片转换成十六进制字符串
     */
    private void setPicToView(Bitmap photo) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        photo.compress(Bitmap.CompressFormat.PNG, 100, stream);// (0 - 100)压缩文件
        byte[] bt = stream.toByteArray();
        photoStr = byte2hex(bt);

        if (bitmap_list.size() < 5) {
            YiJi_Class mYiJi_Class = new YiJi_Class();
            mYiJi_Class.setId(0);
            mYiJi_Class.setBitmap(photo);
            mYiJi_Class.setName(photoStr);
            bitmap_list.add(mYiJi_Class);

        } else {
            Toast.makeText(Main_ChuangJain_ProductActivity.this, "最多上传5张哦", Toast.LENGTH_SHORT).show();
        }
        send_product_MyGridView.setAdapter(mMy_GridView_Adapter);
    }

    public void get_fenlei_tag(final int index) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("cid", cid);

        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.product_tag,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        JSONArray array = response.getJSONArray("data");
                        fenlei_list.clear();
                        if (array.length() == 0) {
                        } else {
                            for (int i = 0; i < array.length(); i++) {
                                JSONObject OBJECT = array.getJSONObject(i);
                                YiJi_Class mYiJi_Class = new YiJi_Class();
                                mYiJi_Class.setId(OBJECT.getInt("id"));
                                mYiJi_Class.setName(OBJECT.getString("name"));
                                fenlei_list.add(mYiJi_Class);
                            }
                            handler.sendEmptyMessage(index);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    public void get_indefine_tag(final int index) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("pid", pid);
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
//        map.put("token", sp.getString("xianji_token", ""));
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.indefine_felei,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        JSONArray array = response.getJSONArray("data");
                        fenlei_list.clear();
                        if (array.length() == 0) {
                        } else {
                            for (int i = 0; i < array.length(); i++) {
                                JSONObject OBJECT = array.getJSONObject(i);
                                YiJi_Class mYiJi_Class = new YiJi_Class();
                                mYiJi_Class.setId(OBJECT.getInt("id"));
                                mYiJi_Class.setName(OBJECT.getString("name"));
                                fenlei_list.add(mYiJi_Class);
                            }
                            handler.sendEmptyMessage(index);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    public void get_product_country_tag(final int index) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.product_country,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        JSONArray array = response.getJSONArray("data");
                        fenlei_list.clear();
                        if (array.length() == 0) {
                        } else {
                            for (int i = 0; i < array.length(); i++) {
                                JSONObject OBJECT = array.getJSONObject(i);
                                YiJi_Class mYiJi_Class = new YiJi_Class();
                                mYiJi_Class.setId(OBJECT.getInt("id"));
                                mYiJi_Class.setName(OBJECT.getString("name"));
                                fenlei_list.add(mYiJi_Class);
                            }
                            handler.sendEmptyMessage(index);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 省份
     */
    public void get_province(final int index) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("pid", province_id);

        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {

                try {
                    if (response.getInt("status") == 1) {
                        fenlei_list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            fenlei_list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(index);
                    } else {
                        Toast.makeText(Main_ChuangJain_ProductActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
                Toast.makeText(Main_ChuangJain_ProductActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 特殊城市
     */
    public void get_special_city(final int index) {
        fenlei_list.clear();
        YiJi_Class mYiJi_Class = new YiJi_Class();
        mYiJi_Class.setId(province_id);
        mYiJi_Class.setName(yiji_product_palce_button.getText().toString());
        fenlei_list.add(mYiJi_Class);
        handler.sendEmptyMessage(index);
    }

    /**
     * 城市
     *
     * @param index
     */

    public void get_city(final int index) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("pid", province_id);
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        fenlei_list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            fenlei_list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(index);
                    } else {
                        Toast.makeText(Main_ChuangJain_ProductActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
                Toast.makeText(Main_ChuangJain_ProductActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 获取地区
     */
    public void get_distrct(final int index) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("pid", city_id);

        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {

                try {
                    if (response.getInt("status") == 1) {
                        fenlei_list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));

                            fenlei_list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(index);
                    } else {
                        Toast.makeText(Main_ChuangJain_ProductActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();


                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
                Toast.makeText(Main_ChuangJain_ProductActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 发布产品
     */
    public void send_product(final int index) {
        for (int i = 0; i < bitmap_list.size(); i++) {
            pic_array.put(bitmap_list.get(i).getName());
        }
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
//        map.put("token", sp.getString("xianji_token", ""));
        map.put("title", edittext_product_name.getText().toString());
        map.put("brand", edittext_product_pingpai.getText().toString());//品牌
        map.put("model", edittext_product_style.getText().toString());//型号
        map.put("parameter", edittext_product_xishu.getText().toString());//参数内容
        map.put("details", edittext_product_content.getText().toString());//产品内容
        map.put("price", edittext_product_price.getText().toString());//产品内容
        map.put("country", product_country_id);//产品所在国
        map.put("parent", yiji_fenlei_id);//父分类
        map.put("category", erji_fenlei_id);//二级分类
        map.put("categorytwo", sanji_fenlei_id);//三级分类
        map.put("categorythree", siji_fenlei_id);//四级分类
        map.put("self_category", indefine_yiji_id);//自定义分类一级
        map.put("self_categorytwo", indefine_erji_id);//自定义分类二级
        map.put("province", province_id);//省份
        map.put("city", city_id);//城市
        map.put("district", distrct_id);//地区
        map.put("upfile", pic_array);
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.send_product,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    Toast.makeText(Main_ChuangJain_ProductActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    if (response.getInt("status") == 1) {
                        pd.cancel();
                        Main_ChuangJain_ProductActivity.this.finish();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(Main_ChuangJain_ProductActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 编辑产品
     *
     * @param index
     */
    public void editor_product(final int index) {
        for (int i = 0; i < bitmap_list.size(); i++) {
            if (bitmap_list.get(i).getName().contains("http")) {
            } else {
                pic_array.put(bitmap_list.get(i).getName());
            }
        }

        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
//        map.put("token", sp.getString("xianji_token", ""));
        map.put("product_id", getIntent().getIntExtra("product_id", 0));
        map.put("title", edittext_product_name.getText().toString());
        map.put("brand", edittext_product_pingpai.getText().toString());//品牌
        map.put("model", edittext_product_style.getText().toString());//型号
        map.put("parameter", edittext_product_xishu.getText().toString());//参数内容
        map.put("details", edittext_product_content.getText().toString());//产品内容
        map.put("price", edittext_product_price.getText().toString());//产品内容
        map.put("country", product_country_id);//产品所在国
        map.put("parent", yiji_fenlei_id);//父分类
        map.put("category", erji_fenlei_id);//二级分类
        map.put("categorytwo", sanji_fenlei_id);//三级分类
        map.put("categorythree", siji_fenlei_id);//四级分类
        map.put("self_category", indefine_yiji_id);//自定义一级分类
        map.put("self_categorytwo", indefine_erji_id);//自定义二级分类
        map.put("province", province_id);//省份
        map.put("city", city_id);//城市
        map.put("district", distrct_id);//地区
        map.put("upfile", pic_array);//新增的图片数组
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.editor_product,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    Toast.makeText(Main_ChuangJain_ProductActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    if (response.getInt("status") == 1) {
                        pd.cancel();
                        Main_ChuangJain_ProductActivity.this.finish();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
						
					/*try {
						
						
					} catch (JSONException e) {
						e.printStackTrace();
					}*/
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(Main_ChuangJain_ProductActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }
//获取编辑页面详情

    public void get_product_detail_tag(final int index) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
//        map.put("token", sp.getString("xianji_token", ""));
        map.put("product_id", getIntent().getIntExtra("product_id", 0));
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.my_product_details,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        JSONObject OBJECT = response.getJSONObject("data");
                        edittext_product_style.setText(OBJECT.getString("model"));
                        edittext_product_name.setText(OBJECT.getString("title"));
                        edittext_product_xishu.setText(OBJECT.getString("parameter"));
                        edittext_product_price.setText(OBJECT.getString("price"));
                        edittext_product_content.setText(OBJECT.getString("details"));
                        edittext_product_pingpai.setText(OBJECT.getString("brand"));
                        yiji_fenlei_id = OBJECT.getInt("parent");
                        erji_fenlei_id = OBJECT.getInt("category");
                        sanji_fenlei_id = OBJECT.getInt("categorytwo");
                        siji_fenlei_id = OBJECT.getInt("categorythree");
                        product_country_id = OBJECT.getInt("country");
                        product_cuntry.setText(OBJECT.getString("country_name"));
                        send_yiji_product_button.setText(OBJECT.getString("parent_name"));//一级分类
                        send_erji_product_button.setText(OBJECT.getString("cat_name"));//二级分类
                        send_sanji_product_button.setText(OBJECT.getString("cattwo_name"));//三级分类
                        send_siji_product_button.setText(OBJECT.getString("catthree_name"));//四级分类
                        if (OBJECT.getString("country_name").equals("中国")) {
                            linearlayout_place.setVisibility(View.VISIBLE);
                            linearlayout_place_name.setVisibility(View.VISIBLE);
                            yiji_product_palce_button.setText(OBJECT.getString("province_name"));//省份
                            erji_product_palce_button.setText(OBJECT.getString("city_name"));//城市
                            sanji_product_palce_button.setText(OBJECT.getString("district_name"));//地区
                            province_id = OBJECT.getInt("province");//省份ID
                            city_id = OBJECT.getInt("city");//城市ID
                            distrct_id = OBJECT.getInt("district");//地区ID
                        } else {
                            linearlayout_place.setVisibility(View.GONE);
                            linearlayout_place_name.setVisibility(View.GONE);
                        }
                        indefine_yiji_id = OBJECT.getInt("self_category");//自定义一级分类
                        indefine_erji_id = OBJECT.getInt("self_categorytwo");//自定义二级分类
                        zidingyi_yiji_product_button.setText(OBJECT.getString("self_name"));
                        zidingyi_erji_product_button.setText(OBJECT.getString("selftwo_name"));
                        if (OBJECT.getString("self_name").length() == 0) {
                            zidingyi_yiji_product_button.setText("请选择");
                        } else {
                            zidingyi_yiji_product_button.setText(OBJECT.getString("self_name"));
                        }
                        if (OBJECT.getString("selftwo_name").length() == 0) {
                            zidingyi_erji_product_button.setText("请选择");
                        } else {
                            zidingyi_erji_product_button.setText(OBJECT.getString("selftwo_name"));
                        }
                        JSONArray pic_array = OBJECT.getJSONArray("produceuploads");
                        for (int i = 0; i < pic_array.length(); i++) {
                            JSONObject pic_obj = pic_array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(pic_obj.getInt("id"));
                            mYiJi_Class.setName(pic_obj.getString("imageurl"));
                            bitmap_list.add(mYiJi_Class);
                        }

                        handler.sendEmptyMessage(index);

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    private void Photo_show() {
        layout = (LinearLayout) LayoutInflater.from(
                Main_ChuangJain_ProductActivity.this).inflate(
                R.layout.information_shoow_photo, null);
        show_listview = (ListView) layout.findViewById(R.id.information_photo_listview);

        show_listview.setCacheColorHint(0);
        WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        show_popupWindow = new PopupWindow(layout, WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT);

        show_popupWindow.setBackgroundDrawable(new BitmapDrawable());


        show_popupWindow.setHeight(wm.getDefaultDisplay().getHeight() / 2);
        show_popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
        show_popupWindow.update();
        show_popupWindow.setOutsideTouchable(true);
        show_popupWindow.setFocusable(true);
        show_popupWindow.setContentView(layout);
    }

    /**
     * 删除图片id
     */
    public void delete_product_pic(final int id, final int position) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
//        map.put("token", sp.getString("xianji_token", ""));
        map.put("product_id", getIntent().getIntExtra("product_id", 0));
        map.put("upload_id", id);
        Log.i("idididiidd", id + "");
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.delete_product_pic,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    Toast.makeText(Main_ChuangJain_ProductActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    if (response.getInt("status") == 1) {
                        bitmap_list.remove(position);
                        mMy_GridView_Adapter.notifyDataSetChanged();
                    } else {
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(Main_ChuangJain_ProductActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }

    class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return fenlei_list.size();
        }

        @Override
        public Object getItem(int arg0) {
            return arg0;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder mHolder;
            if (convertView == null) {
                mHolder = new Holder();
                convertView = View.inflate(Main_ChuangJain_ProductActivity.this, R.layout.listview_item_layout, null);
                mHolder.place_text = (TextView) convertView.findViewById(R.id.place_text);
                convertView.setTag(mHolder);
            }
            mHolder = (Holder) convertView.getTag();
            mHolder.place_text.setText(fenlei_list.get(position).getName());
            return convertView;
        }
    }

    class Holder {
        TextView place_text;
    }

    class My_GridView_Adapter extends BaseAdapter {

        @Override
        public int getCount() {
            return bitmap_list.size();
        }

        @Override
        public Object getItem(int arg0) {
            return arg0;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Gridview_Holder mHolder;
            if (convertView == null) {
                mHolder = new Gridview_Holder();
                convertView = View.inflate(Main_ChuangJain_ProductActivity.this, R.layout.gridview_item, null);
                mHolder.gridview_imageview = (ImageView) convertView.findViewById(R.id.gridview_imageview);
                mHolder.delete_product_pic = (ImageView) convertView.findViewById(R.id.delete_product_pic);

                convertView.setTag(mHolder);
            }
            mHolder = (Gridview_Holder) convertView.getTag();
            if (bitmap_list.get(position).getId() == 0) {
                mHolder.gridview_imageview.setImageBitmap(bitmap_list.get(position).getBitmap());
            } else {
                ImageLoader.getInstance().displayImage(bitmap_list.get(position).getName(), mHolder.gridview_imageview);
            }
            final int a = position;
            mHolder.delete_product_pic.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (bitmap_list.get(a).getId() != 0) {
                        delete_product_pic(bitmap_list.get(a).getId(), a);
                    } else {
                        bitmap_list.remove(a);
                    }
                    notifyDataSetChanged();
                }
            });
            return convertView;
        }
    }

    class Gridview_Holder {
        ImageView gridview_imageview, delete_product_pic;
    }
}
